/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __t3_destination_analysis.c                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/05 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include <t3/t3_core.h>
#include <t3/t3_analysis.h>
#include <t3/t3_ejb.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "../../../src/module/t3/config.h"
#include "../../../src/lib/report/frreport_dbg.h"

extern int __t3_destination_analysis(L7session_t3_private *p_st_private
                                                             , Frbyte_Packet *p_st_data);
extern L7session_t3_private* __t3_private_create(void);

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void case1(void)
{
    Frbyte_Packet *p_st_data = NULL;
    L7session_t3_private *p_st_private = NULL;
    int i_ret = 0;

    p_st_private = __t3_private_create();

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x00\x00\x01\x01\x00\x00\x00\x01\x00\x00\x13\x08\xb6\x41\x00\x01\x00\x0c\x65\x78\x61\x6d\x70\x6c\x65\x73\x2d\x6a\x6d\x73\x01\x00\x03\x41\x6c\x6c\x02\x02\x13\xf7\xa1\x50\xa8\x06\xc8\xc1\x00\x00\x00\x0c\x02\x00\x0b\x41\x64\x6d\x69\x6e\x53\x65\x72\x76\x65\x72\x00\x2d\x84\x1a\x02\x13\xf7\xa1\x50\xa8\x06\xc8\xc1\x00\x00\x00\x17\x02\x00\x0b\x41\x64\x6d\x69\x6e\x53\x65\x72\x76\x65\x72\x00\x2d\x84\x1a\x00\x01\x00\x0b\x46\x69\x6c\x65\x53\x74\x6f\x72\x65\x2d\x30", 229);

    i_ret = __t3_destination_analysis(p_st_private, p_st_data);

    L7Session_t3 *p_st_session = NULL;
    p_st_session = p_st_private->p_st_session;

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    //CU_ASSERT_STRING_EQUAL(p_st_session->p_jms_module, "examples-jms");
    //CU_ASSERT_STRING_EQUAL(p_st_session->p_weblogic_server, "AdminServer");
    CU_ASSERT_EQUAL(p_st_private->is_topic, 0);

    bytebuff_free(&p_st_data);
    t3_session_destroy(p_st_private);

    return;
}

static void case2(void)
{
    Frbyte_Packet *p_st_data = NULL;
    L7session_t3_private *p_st_private = NULL;
    int i_ret = 0;

    p_st_private = __t3_private_create();

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x00\x00\x01\x01\x00\x00\x00\x01\x00\x00\x13\x08\xb6\x42\x00\x01\x00\x0c\x65\x78\x61\x6d\x70\x6c\x65\x73\x2d\x6a\x6d\x73\x01\x00\x03\x41\x6c\x6c\x02\x02\x13\xf7\xa1\x50\xa8\x06\xc8\xc1\x00\x00\x00\x0c\x02\x00\x0b\x41\x64\x6d\x69\x6e\x53\x65\x72\x76\x65\x72\x00\x2d\x84\x1a\x02\x13\xf7\xa1\x50\xa8\x06\xc8\xc1\x00\x00\x01\x47\x02\x00\x0b\x41\x64\x6d\x69\x6e\x53\x65\x72\x76\x65\x72\x00\x2d\x84\x1a\x00\x01\x00\x0b\x46\x69\x6c\x65\x53\x74\x6f\x72\x65\x2d\x30", 229);

    i_ret = __t3_destination_analysis(p_st_private, p_st_data);

    L7Session_t3 *p_st_session = NULL;
    p_st_session = p_st_private->p_st_session;

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    //CU_ASSERT_STRING_EQUAL(p_st_session->p_jms_module, "examples-jms");
    //CU_ASSERT_STRING_EQUAL(p_st_session->p_weblogic_server, "AdminServer");
    CU_ASSERT_EQUAL(p_st_private->is_topic, 0);

    bytebuff_free(&p_st_data);
    t3_session_destroy(p_st_private);

    return;
}

int add_suite__t3_destination_analysis(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __t3_destination_analysis()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
